import cv2
from _0work_tools import cv_show
from _0work_tools import box_filter_factor
from _03fulfill import fulfill_border
from _0work_tools import img_box_operate
from _0work_tools import img_merge
from _0work_tools import img_add
from _02threshold import thresh_operate
"""
@Project: pythonPro1
@Name: _07laplace.py
@Author: linxin_liu
@Date: 2022/10/16 15:35
拉普拉斯、
"""


def laplace(img, box_types):
    if box_types == 'laplace_com':
        box_filter = box_filter_factor([3, 3], 0)  # 元素都是0的3*3盒子
        box_filter[0][1], box_filter[1][0], box_filter[1][2], box_filter[2][1] = 1, 1, 1, 1
        box_filter[1][1] = -4  # 拉普拉斯滤波器模板。
        img_box_operate(img, box_filter)
    elif box_types == 'laplace_around':
        box_filter = box_filter_factor([3, 3], 1)  # 元素都是1的3*3盒子
        box_filter[1][1] = -8  # around拉普拉斯滤波器模板。
        img_box_operate(img, box_filter)
    elif box_types == 'sobel_up_down':
        box_filter = box_filter_factor([3, 3], 0)  # 元素都是0的3*3盒子
        box_filter[0][0], box_filter[0][1], box_filter[0][2] = -1, -2, -1
        box_filter[2][0], box_filter[2][1], box_filter[2][2] = 1, 2, 1,
        img_box_operate(img, box_filter)
        thresh_operate(127, img, 'Binary')
    elif box_types == 'sobel_left_right':
        box_filter = box_filter_factor([3, 3], 0)  # 元素都是0的3*3盒子
        box_filter[0][0], box_filter[1][0], box_filter[2][0] = -1, -2, -1
        box_filter[2][0], box_filter[2][1], box_filter[2][2] = 1, 2, 1
        img_box_operate(img, box_filter)
    return img


if __name__ == '__main__':
    img_original = cv2.imread('D:/tools/image_operation/bing.png')
    img_g = img_original[:, :, 0]
    img_b = img_original[:, :, 1]
    img_r = img_original[:, :, 2]
    img_after_g = laplace(img_g, 'sobel_up_down')
    img_after_b = laplace(img_b, 'sobel_up_down')
    img_after_r = laplace(img_r, 'sobel_up_down')
    # img_my_merge = img_merge(img_original, img_g, img_b, img_r)
    # laplace,不求余：单图(纯灰色，有轮廓)，三图融合+原图==有一点失真。
    # laplace,  求余：单图(纯灰色，有轮廓)，三图融合+原图==有一点失真。
    # laplace_around,不求余：单图(纯灰色，有轮廓)，三图融合+原图==有一点失真。
    # img_merge = cv2.merge((img_after_b, img_after_g, img_after_r))
    img_original_2 = cv2.imread('D:/tools/image_operation/bing.png')
    cv2.imwrite('D:/tools/image_operation/bing_so1.png', img_after_g)
    # cv2.imwrite('D:/tools/image_operation/bing_1.png', img_after_r)